package com.zlzxm.lock;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


/**
 * Created by zlz
 * on  2019-10-14
 */
public class NotificationView extends AppCompatTextView {

    Handler handler = new Handler(Looper.myLooper());

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault());


    public NotificationView(Context context) {
        this(context,null);
    }

    public NotificationView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public NotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        handler.postDelayed(new TimerRunable(),1000);
    }







    class TimerRunable implements Runnable{


        @Override
        public void run() {

            Date date = new Date();

            String content = simpleDateFormat.format(date);

            setText(content);

            handler.postDelayed(this,3000);

        }
    }
}
